package com.gr.experimental.model.impl.distr;

import com.gr.experimental.model.impl.distr.operations.CalculationException;
import com.gr.experimental.model.impl.distr.operations.Expression;

public class ContextAccess implements Assignable, Expression{

	Descriptor descriptor;

	public ContextAccess(Descriptor descriptor) {
		this.descriptor = descriptor;
	}

	@Override
	public void assign(Context context, Object value) throws AssignmentException {
		if (descriptor.isModifiable() == false) {
			throw new AssignmentException("Object " 
					+ descriptor.getSymbolName() + " not modifiable");
		}
		context.setVariableValue(descriptor.getSymbolName(), value);
	}

	@Override
	public Object getValue(Context context) throws CalculationException {
		return context.getVariableValue(descriptor.getSymbolName());
	}

	@Override
	public Class<?> getValueType() {
		return descriptor.getType();
	}
	
}
